﻿#region

using System;
using System.Collections.Generic;
using MediaSage.Lib.Configuration;
using MediaSage.Lib.Database;

#endregion

namespace MediaSage.Lib
{
    #region Enumerations

    public enum EMediaType
    {
        undef,
        TV,
        MOVIE,
        AUDIO
    }

    #endregion Enumerations

    public class MediaClass
    {
        #region Fields

        private readonly Config config;
        private readonly MediaDatabase databaseObject;
        private readonly Logger logger;
        public VideoEntity videoEntity;

        #endregion Fields

        #region Constructors

        public MediaClass(Config Config)
        {
            config = Config;
            logger = Config.Logger;

            videoEntity = new VideoEntity();

            databaseObject = new MediaDatabase(config);

            logger.Log("CMediaClass Initalized");
        }

        #endregion Constructors

        #region Properties

        public string DVDId
        {
            get { return videoEntity.DVDId; }
            set { videoEntity.DVDId = value; }
        }

        public ImageEntity Backdrop
        {
            get { return videoEntity.Backdrop; }
            set { videoEntity.Backdrop = value; }
        }

        public ImageEntity Poster
        {
            get { return videoEntity.Poster; }
            set { videoEntity.Poster = value; }
        }

        public IList<SimilarItemEntity> SimilarItems
        {
            get { return videoEntity.SimilarItems; }
            set { videoEntity.SimilarItems = value; }
        }

        public bool Adult
        {
            get { return videoEntity.Adult; }
            set { videoEntity.Adult = value; }
        }

        public IList<string> AltName
        {
            get { return videoEntity.AltNames; }
            set { videoEntity.AltNames = value; }
        }

        public int AudioBitrate
        {
            get { return videoEntity.AudioBitrate; }
            set { videoEntity.AudioBitrate = value; }
        }

        public int AudioChannels
        {
            get { return videoEntity.AudioChannels; }
            set { videoEntity.AudioChannels = value; }
        }

        public string AudioCodec
        {
            get { return videoEntity.AudioCodec; }
            set { videoEntity.AudioCodec = value; }
        }

        public string AudioCodecRaw
        {
            get { return videoEntity.AudioCodecRaw; }
            set { videoEntity.AudioCodecRaw = value; }
        }

        public long AudioFrequency
        {
            get { return videoEntity.AudioFrequency; }
            set { videoEntity.AudioFrequency = value; }
        }

        public string Budget
        {
            get { return videoEntity.Budget; }
            set { videoEntity.Budget = value; }
        }

        public IList<PersonEntity> Cast
        {
            get { return videoEntity.Cast; }
            set { videoEntity.Cast = value; }
        }

        public IList<string> Categories
        {
            get { return videoEntity.Categories; }
            set { videoEntity.Categories = value; }
        }

        public IList<CertificationEntity> Certifications
        {
            get { return videoEntity.Certifications; }
            set { videoEntity.Certifications = value; }
        }

        public bool ContentProtected
        {
            get { return videoEntity.ContentProtected; }
            set { videoEntity.ContentProtected = value; }
        }

        public IList<string> Countries
        {
            get { return videoEntity.Countries; }
            set { videoEntity.Countries = value; }
        }

        public string Description
        {
            get { return videoEntity.Description; }
            set { videoEntity.Description = value; }
        }

        public IList<string> Distributors
        {
            get { return videoEntity.Distributors; }
            set { videoEntity.Distributors = value; }
        }

        public IList<EpisodeEntity> Episodes
        {
            get { return videoEntity.Episodes; }
            set { videoEntity.Episodes = value; }
        }

        public string Filename
        {
            get { return videoEntity.Filename; }
            set { videoEntity.Filename = value; }
        }

        public IList<string> Genre
        {
            get { return videoEntity.Genre; }
            set { videoEntity.Genre = value; }
        }

        public IList<ImageEntity> Images
        {
            get { return videoEntity.Images; }
            set { videoEntity.Images = value; }
        }

        public string IMDBID
        {
            get { return videoEntity.IMDBID; }
            set { videoEntity.IMDBID = value; }
        }

        public bool IsDelay
        {
            get { return videoEntity.IsDelay; }
            set { videoEntity.IsDelay = value; }
        }

        public bool IsFinale
        {
            get { return videoEntity.IsFinale; }
            set { videoEntity.IsFinale = value; }
        }

        public bool IsHDContent
        {
            get { return videoEntity.IsHDContent; }
            set { videoEntity.IsHDContent = value; }
        }

        public bool IsLive
        {
            get { return videoEntity.IsLive; }
            set { videoEntity.IsLive = value; }
        }

        public bool IsMovie
        {
            get { return videoEntity.IsMovie; }
            set { videoEntity.IsMovie = value; }
        }

        public bool IsPremire
        {
            get { return videoEntity.isPremire; }
            set { videoEntity.isPremire = value; }
        }

        public bool IsRepeat
        {
            get { return videoEntity.IsRepeat; }
            set { videoEntity.IsRepeat = value; }
        }

        public bool IsSAP
        {
            get { return videoEntity.IsSAP; }
            set { videoEntity.IsSAP = value; }
        }

        public bool IsSport
        {
            get { return videoEntity.IsSport; }
            set { videoEntity.IsSport = value; }
        }

        public bool IsSubtitled
        {
            get { return videoEntity.isSubtitled; }
            set { videoEntity.isSubtitled = value; }
        }

        public bool IsTVSeries
        {
            get { return videoEntity.IsTVSeries; }
            set { videoEntity.IsTVSeries = value; }
        }

        public IList<string> Languages
        {
            get { return videoEntity.Languages; }
            set { videoEntity.Languages = value; }
        }

        public DateTime? LastModified
        {
            get { return videoEntity.LastModified; }
            set { videoEntity.LastModified = value; }
        }

        public EMediaType MediaType { get; set; }

        public IList<MetadataEntity> Metadata
        {
            get { return videoEntity.Metadata; }
            set { videoEntity.Metadata = value; }
        }

        public string MPAARating
        {
            get { return videoEntity.MPAARating; }
            set { videoEntity.MPAARating = value; }
        }

        public string Name
        {
            get { return videoEntity.Name; }
            set { videoEntity.Name = value; }
        }

        public string NetworkAffiliation
        {
            get { return videoEntity.NetworkAffiliation; }
            set { videoEntity.NetworkAffiliation = value; }
        }

        public DateTime? OriginalBroadcastTime
        {
            get { return videoEntity.OriginalBroadcastTime; }
            set { videoEntity.OriginalBroadcastTime = value; }
        }

        public string Overview
        {
            get { return videoEntity.Overview; }
            set { videoEntity.Overview = value; }
        }

        public string ParentalRating
        {
            get { return videoEntity.ParentalRating; }
            set { videoEntity.ParentalRating = value; }
        }

        public double Popularity
        {
            get { return videoEntity.Popularity; }
            set { videoEntity.Popularity = value; }
        }

        public double Rating
        {
            get { return videoEntity.Rating; }
            set { videoEntity.Rating = value; }
        }

        public DateTime? Released
        {
            get { return videoEntity.Released; }
            set { videoEntity.Released = value; }
        }

        public string Revenue
        {
            get { return videoEntity.Revenue; }
            set { videoEntity.Revenue = value; }
        }

        public int RottenTomatosID
        {
            get { return videoEntity.RottenTomatosID; }
            set { videoEntity.RottenTomatosID = value; }
        }

        public TimeSpan RunTime
        {
            get { return videoEntity.RunTime; }
            set { videoEntity.RunTime = value; }
        }

        public double Score
        {
            get { return videoEntity.Score; }
            set { videoEntity.Score = value; }
        }

        public IList<DayOfWeek?> SeriesAirsDaysOfWeek
        {
            get { return videoEntity.SeriesAirsDaysOfWeek; }
            set { videoEntity.SeriesAirsDaysOfWeek = value; }
        }

        /// <summary>
        /// Only the hour/minute is used, everything else is ignored
        /// </summary>
        public DateTime? SeriesAirsTime
        {
            get { return videoEntity.SeriesAirsTime; }
            set { videoEntity.SeriesAirsTime = value; }
        }

        public int SeriesID
        {
            get { return videoEntity.SeriesID; }
            set { videoEntity.SeriesID = value; }
        }

        public string StationName
        {
            get { return videoEntity.StationName; }
            set { videoEntity.StationName = value; }
        }

        public IList<string> Studios
        {
            get { return videoEntity.Studios; }
            set { videoEntity.Studios = value; }
        }

        public string Subtitle
        {
            get { return videoEntity.Subtitle; }
            set { videoEntity.Subtitle = value; }
        }

        public string Title
        {
            get { return videoEntity.Name; }
            set { videoEntity.Name = value; }
        }

        public int TmdbID
        {
            get { return videoEntity.TmdbID; }
            set { videoEntity.TmdbID = value; }
        }

        public string Trailer
        {
            get { return videoEntity.Trailer; }
            set { videoEntity.Trailer = value; }
        }

        public bool Translated
        {
            get { return videoEntity.Translated; }
            set { videoEntity.Translated = value; }
        }

        public int TvdbID
        {
            get { return videoEntity.TvdbID; }
            set { videoEntity.TvdbID = value; }
        }

        public string URL
        {
            get { return videoEntity.URL; }
            set { videoEntity.URL = value; }
        }

        public string VideoAspect
        {
            get { return videoEntity.VideoAspect; }
            set { videoEntity.VideoAspect = value; }
        }

        public float VideoBitrate
        {
            get { return videoEntity.VideoBitrate; }
            set { videoEntity.VideoBitrate = value; }
        }

        public string VideoBitRateMode
        {
            get { return videoEntity.VideoBitRateMode; }
            set { videoEntity.VideoBitRateMode = value; }
        }

        public string VideoCodec
        {
            get { return videoEntity.VideoCodec; }
            set { videoEntity.VideoCodec = value; }
        }

        public string VideoCodecVersion
        {
            get { return videoEntity.VideoCodecVersion; }
            set { videoEntity.VideoCodecVersion = value; }
        }

        public long VideoFileSize
        {
            get { return videoEntity.VideoFilesize; }
            set { videoEntity.VideoFilesize = value; }
        }

        public float VideoFrameRate
        {
            get { return videoEntity.VideoFrameRate; }
            set { videoEntity.VideoFrameRate = value; }
        }

        public int VideoHeight
        {
            get { return videoEntity.VideoHeight; }
            set { videoEntity.VideoHeight = value; }
        }

        public TimeSpan VideoLength
        {
            get { return videoEntity.VideoLength; }
            set { videoEntity.VideoLength = value; }
        }

        public string VideoQuality
        {
            get { return videoEntity.VideoQuality; }
            set { videoEntity.VideoQuality = value; }
        }

        public int VideoWidth
        {
            get { return videoEntity.VideoWidth; }
            set { videoEntity.VideoWidth = value; }
        }

        #endregion Properties

        #region Methods

        public bool StoreToDatabase()
        {
            config.Logger.Log("Entering MediaClass.StoreToDatabase()");

            //videoEntity.SaveOrUpdate();
            if (!databaseObject.SaveToDatabase(videoEntity))
            {
                logger.Log(Logger.Levels.ERROR, "Failed to save to the database.");
                logger.Log("Exiting StoreToDatabase(), rc==false");
                return false;
            }
            return true;
        }

        #endregion Methods
    }
}